/**
 * æ¶é´å¸®å©ç±»
 */
function SysDateUtil() {
	
	//è·åè¿6ä¸ªæçæ¶é´
	this.getNewSixMonth = function (){
		//åå»ºç°å¨çæ¶é´
		var data=new Date();
		//è·åå¹´
		var year=data.getFullYear();
		//è·åæ
		var mon=data.getMonth()+1;
		var arry=new Array();
		if(mon<10){
			arry[0]=year+"-"+"0"+mon;
		}else{
			arry[0]=year+"-"+mon;
		}
		for(var i=1;i<6;i++){
			mon=mon-1;
			if(mon<=0){
				year=year-1;
				mon=mon+12;
			}
			if(mon<10){
				mon="0"+mon;
			}
			arry[i]=year+"-"+mon;
		}
		
		return arry;
	}
	//è·åå»å¹´åæ6ä¸ªæçæ¶é´
	this.getLastYearSixMonth = function (){
		//åå»ºç°å¨çæ¶é´
		var data=new Date();
		//è·åå¹´
		var year=data.getFullYear()-1;
		//è·åæ
		var mon=data.getMonth()+1;
		var arry=new Array();
		if(mon<10){
			arry[0]=year+"-"+"0"+mon;
		}else{
			arry[0]=year+"-"+mon;
		}
		for(var i=1;i<6;i++){
			mon=mon-1;
			if(mon<=0){
				year=year-1;
				mon=mon+12;
			}
			if(mon<10){
				mon="0"+mon;
			}
			arry[i]=year+"-"+mon;
		}
		
		return arry;
	}
	
	/**
	 * è·ååå å¤©è·ç¦»ä»å¤©çæ¶é´
	 */
	this.getDateDiff = function(dateTimeStamp) {
		var minute = 1000 * 60;
		var hour = minute * 60;
		var day = hour * 24;
		var halfamonth = day * 15;
		var month = day * 30;
		var now = new Date().getTime();
		var diffValue = now - dateTimeStamp;
		if (diffValue < 0) {
			return;
		}
		var monthC = diffValue / month;
		var weekC = diffValue / (7 * day);
		var dayC = diffValue / day;
		var hourC = diffValue / hour;
		var minC = diffValue / minute;
		if (monthC >= 1) {
			result = "" + parseInt(monthC) + "æå";
		} else if (weekC >= 1) {
			result = "" + parseInt(weekC) + "å¨å";
		} else if (dayC >= 1) {
			result = "" + parseInt(dayC) + "å¤©å";
		} else if (hourC >= 1) {
			result = "" + parseInt(hourC) + "å°æ¶å";
		} else if (minC >= 1) {
			result = "" + parseInt(minC) + "åéå";
		} else {
			result = "åå";
		}
		return result;
	}, this.getDateTimeStamp = function(dateStr) {
		return Date.parse(dateStr.replace(/-/gi, "/"));
	},

	//è·åå½åçæ¥ææ¶é´ æ ¼å¼âyyyy-MM-dd HH:MM:SSâ
	this.getNowFormatDate = function(time) {
		var date = time || new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		var getHours = date.getHours();
		var getMinutes = date.getMinutes();
		var getSeconds = date.getSeconds();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}

		if (getHours >= 0 && getHours <= 9) {
			getHours = "0" + getHours;
		}

		if (getMinutes >= 0 && getMinutes <= 9) {
			getMinutes = "0" + getMinutes;
		}
		if (getSeconds >= 0 && getSeconds <= 9) {
			getSeconds = "0" + getSeconds;
		}

		var currentdate = date.getFullYear() + seperator1 + month + seperator1
				+ strDate + " " + getHours + seperator2 + getMinutes
				+ seperator2 + getSeconds;
		return currentdate;
	}
	//è·åå½åçæ¥ææ¶é´ æ ¼å¼âyyyy-MM-ddâ
	this.getDataYMD = function(time) {
		var date = time || new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		var getHours = date.getHours();
		var getMinutes = date.getMinutes();
		var getSeconds = date.getSeconds();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		
		
		var currentdate = date.getFullYear() + seperator1 + month + seperator1
		+ strDate ;
		return currentdate;
	}

	//æ¯è¾æ¥ææ¶é´å¤§å°
	this.compareTime = function(startDate, endDate) {
		if (startDate.length > 0 && endDate.length > 0) {
			var startDateTemp = startDate.split(" ");
			var endDateTemp = endDate.split(" ");
			var arrStartDate = startDateTemp[0].toString().split("-");
			var arrEndDate = endDateTemp[0].toString().split("-");

			var arrStartTime = startDateTemp[1].toString().split(":");
			var arrEndTime = endDateTemp[1].toString().split(":");

			var allStartDate = new Date(arrStartDate[0], arrStartDate[1],
					arrStartDate[2], arrStartTime[0], arrStartTime[1],
					arrStartTime[2]);
			var allEndDate = new Date(arrEndDate[0], arrEndDate[1],
					arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);
			console.log(allStartDate.getTime());
			console.log(allEndDate.getTime());

			if (allStartDate.getTime() > allEndDate.getTime()) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	//è®¡ç®æ¶é´å·®
	this.timedifference = function(startDate, endDate) {
		var date1 = new Date(startDate); //å¼å§æ¶é´
		var date2 = new Date(endDate); //ç»ææ¶é´
		var date3 = date1.getTime() - date2.getTime(); //æ¶é´å·®ç§
		var days = Math.floor(date3 / (24 * 3600 * 1000));

		var leave1 = date3 % (24 * 3600 * 1000);//è®¡ç®å¤©æ°åå©ä½çæ¯«ç§æ°
		var hours = Math.floor(leave1 / (3600 * 1000));

		var leave2 = leave1 % (3600 * 1000); //è®¡ç®å°æ¶æ°åå©ä½çæ¯«ç§æ°
		var minutes = Math.floor(leave2 / (60 * 1000));

		var leave3 = leave2 % (60 * 1000); //è®¡ç®åéæ°åå©ä½çæ¯«ç§æ°
		var seconds = Math.round(leave3 / 1000);

		return "æ¶é´å·®" + days + "å¤©" + hours + "æ¶" + minutes + "å" + seconds + "ç§";

	},
	
	this.getMinuteTimeDifference = function(time1,time2){//è®¡ç®ä¸¤ä¸ªæ¶é´çç¸å·®å¤å°åé
		if(time1>time2)
		{
		  alert("å¼å§æ¶é´ä¸è½å¤§äºç»ææ¶é´ï¼");
		  return false;
		}
		var begin1=time1.substr(0,10).split("-");
		var end1=time2.substr(0,10).split("-");
		var date1=new Date(begin1[1] + - + begin1[2] + - + begin1[0]);
		var date2=new Date(end1[1] + - + end1[2] + - + end1[0]);
		var m=parseInt(Math.abs(date2-date1)/1000/60);
		var min1=parseInt(time1.substr(11,2))*60+parseInt(time1.substr(14,2));
		var min2=parseInt(time2.substr(11,2))*60+parseInt(time2.substr(14,2));
		var n=min2-min1;
		var minutes=m+n;
		return minutes;
	},
	this.getWeekDay = function(){//è·åå¨å 
		
		var a = new Array("æ¥", "ä¸", "äº", "ä¸", "å", "äº", "å­");  
		var week = new Date().getDay();  
		var str = "ææ"+ a[week];  
		return str;
	},
	this.getShowTime = function(){
		var myDate = new Date;
		var year = myDate.getFullYear(); //è·åå½åå¹´
		var mon = myDate.getMonth() + 1; //è·åå½åæ
		var date = myDate.getDate(); //è·åå½åæ¥
		var week = myDate.getDay();
		var weeks = ["æææ¥", "ææä¸", "ææäº", "ææä¸", "ææå", "ææäº", "ææå­"];
		return year + "å¹´" + mon + "æ" + date + "æ¥ã" + weeks[week];
	}
	
	
    this.date2Str = function(date, separator){
    	if(separator === undefined){
    		separator = "-";
    	}
    	 var y = date.getFullYear();
         var m = date.getMonth() + 1;
         var d = date.getDate();
         return y + separator + (m < 10? "0": "") + m + separator + (d < 10? "0": "") + d;
    }
	
}

window.sdu = $.sysDateUtil = $.sdu = new SysDateUtil();

